#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std; 

struct farmer_t {
	int p, a; 
}; 

bool cmp(farmer_t &a, farmer_t &b)
{
	return a.p<b.p; 
}

int main()
{
	vector<farmer_t> a; 
	unsigned n, m, i, sum, cost, r=0; 
	
	//freopen("p1208.in", "r", stdin); 
	cin>>n>>m; 

	a.resize(m); 
	for (i=0; i<m; i++) {
		cin>>a[i].p>>a[i].a; 
	}
	sort(a.begin(), a.end(), cmp); 
	sum = 0; 
	cost = 0; 
	for (i=0; i<m; i++) {
		if (sum+a[i].a<n) {
			sum += a[i].a; 
			cost += a[i].a*a[i].p; 
		} else {
			cost += a[i].p*(n-sum); 
			sum = n; 
			break; 
		}
	}
	cout<<cost<<endl; 
	return 0; 
}

